#include "widget.h"
#include "ui_widget.h"

#include <QFileDialog>
#include <QString>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->lineEditRecFile->setText("D:\\");

    my_socket->g_root_dir = ui->lineEditRecFile->text();
}

Widget::~Widget()
{
    delete ui;
}

//改变默认文件存储路径
void Widget::on_toolButtonListenSavePath_clicked()
{
    //获取文件路径
    QString str = QFileDialog::getExistingDirectory(this, "选择保存路径", "D:/");
    ui->lineEditRecFile->setText(str);
    //重置默认文件保存路径
    my_socket->g_root_dir = ui->lineEditRecFile->text();
}

//监听按钮
void Widget::on_toolButtonListen_clicked()
{
    QString str = ui->lineEditListenPort->text();
    quint16 port = str.toUShort();

    emit my_listen_signal(port);
}

////当按下监听按钮时，开始运行run函数，开始监听端口
//void(Widget::*lisSignal)(quint16) = &Widget::my_listen_signal;
//void(FileServer::*lisSlot)(quint16) = &FileServer::run;
//connect(mywidget, lisSignal, this, lisSlot);

////当接收端(服务器)检测到有新的连接成功后，会建立与发送端传输的socket套接字
//connect(this, &QTcpServer::newConnection, this, &FileServer::new_client);

//void(FileServer::*connSignal)(qintptr) = &FileServer::mynewConnection;
//void(FileServer::*connSlot)(qintptr) = &FileServer::incomingConnection;
//connect(this, connSignal, this, connSlot);
